package com.linh.location;

import java.io.Serializable;

public class BusRoute implements Serializable, Comparable<BusRoute> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	String towards;
	String destinationName;
	String routeId;
	long estimatedTime;

	public BusRoute(String towards, String destinationName, String routeId,
			long estimatedTime) {
		super();
		this.towards = towards;
		this.destinationName = destinationName;
		this.routeId = routeId;
		this.estimatedTime = estimatedTime;
	}

	public String getTowards() {
		return towards;
	}

	public void setTowards(String towards) {
		this.towards = towards;
	}

	public String getDestinationName() {
		return destinationName;
	}

	public void setDestinationName(String destinationName) {
		this.destinationName = destinationName;
	}

	public String getRouteId() {
		return routeId;
	}

	public void setRouteId(String routeId) {
		this.routeId = routeId;
	}

	public long getEstimatedTime() {
		return estimatedTime;
	}

	public void setEstimatedTime(long estimatedTime) {
		this.estimatedTime = estimatedTime;
	}

	@Override
	public String toString() {
		return "BusRoute [towards=" + towards + ", destinationName="
				+ destinationName + ", routeId=" + routeId + ", estimatedTime="
				+ estimatedTime + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((routeId == null) ? 0 : routeId.hashCode());
		return result;
	}

	public int getWaitingTime() {
		int waitInsec = (int) ((getEstimatedTime() - System.currentTimeMillis()) / 1000);
		return waitInsec;

	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		BusRoute other = (BusRoute) obj;
		if (routeId == null) {
			if (other.routeId != null)
				return false;
		} else if (!routeId.equals(other.routeId))
			return false;
		return true;
	}

	@Override
	public int compareTo(BusRoute another) {
		if (getEstimatedTime() < another.getEstimatedTime()) {
			return -1;
		} else {
			return 1;
		}
	}

}
